import { on, once } from "@/utils/utils";

export default {
  bind(el, binding, vnode) {
    let startTimer;
    let interval = null;

    const clear = () => {
      if (Date.now() - startTimer < 100) {
        handler();
      }
      clearInterval(interval);
      interval = null;
    };
    const handler = () => vnode.context[binding.expression].apply();
    on(el, "mousedown", (e) => {
      if (e.button !== 0) return;
      startTimer = Date.now();
      clearInterval(interval);
      once(document, "mouseup", clear);
      interval = setInterval(handler, 100);
    });
  },
};
